w2n = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

def words_to_num(words):
    try:
        return sum(w2n[word] * 10**i for i, word in enumerate(reversed(words)))
    except KeyError:
        return None

def closest_prime(num):
    if is_prime(num):
        return num
    shift = 1
    while True:
        if is_prime(num - shift):
            return num - shift
        if is_prime(num + shift):
            return num + shift
        shift += 1

def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

input_words = input().strip().split()
if len(input_words) == 3:
    n = words_to_num(input_words)
    if n is not None:
        print(closest_prime(n))
    else:
        print("Wrong input")
else:
    print("Wrong input")
